﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataModel;

namespace ApplicationServer
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!User.Identity.IsAuthenticated)
            {
                Response.Redirect("Account/Login.aspx");
            }
            else
            {
                if (!Request.Browser.IsMobileDevice)
                {
                    
                }
            }

            if (!this.IsPostBack)
            {
                K8055Data data = TicketManager.Get(Application);
                SetDeviceState(0, data.OutputPin1);
                SetDeviceState(1, data.OutputPin2);
                SetDeviceState(2, data.OutputPin3);
                SetDeviceState(3, data.OutputPin4);
                SetDeviceState(4, data.OutputPin5);
                SetDeviceState(5, data.OutputPin6);
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            K8055Data data = TicketManager.Get(Application);
            data.OutputPin1 = GetDeviceState(0);
            data.OutputPin2 = GetDeviceState(1);
            data.OutputPin3 = GetDeviceState(2);
            data.OutputPin4 = GetDeviceState(3);
            data.OutputPin5 = GetDeviceState(4);
            data.OutputPin6 = GetDeviceState(5);
            TicketManager.Set(Application, data);
            Response.Redirect("~/Done.aspx");
        }

        private void SetDeviceState(int index, bool value)
        {
            CheckBoxList1.Items[index].Selected = value;
        }

        private bool GetDeviceState(int index)
        {
            return CheckBoxList1.Items[index].Selected;
        }
    }
}
